#! /bin/bash

checkError() {
    error=$?

    if [ $error -ne 0 ]; then
        echo "found error: $error"
        exit $error
    fi
}

program_name=my-golang-app

echo "cleaning ..."
rm -rf ./dist
go clean
checkError

echo "generating docs ..."
swag init
checkError

echo "building ..."
mkdir -p ./dist
checkError

# Windows
# go build -o ./dist/$program_name
# Linux
env GOOS=linux GOARCH=amd64 go build -o ./dist/$program_name
checkError

cp -r ./conf ./dist/
checkError

echo "packaging"
tar  --owner=0 --group=0 --no-same-owner -pjcvf $program_name.tar.bz2 dist/
